﻿using System;
using System.Windows;
using System.Windows.Controls;
using Kurax.BoardGames.Client.Engine;
using Kurax.BoardGames.Client.Engine.Commands.General;

namespace Kurax.BoardGames.Client {
    public partial class MainPage {
        private readonly Network network;

        public MainPage() {
            this.InitializeComponent();
            this.network = new Network();
            this.network.ConnectComplete += (sender, e) => this.Dispatcher.BeginInvoke(() => {
                this.Button1.Content = this.network.LastOperationMessage;
                this.Button2.IsEnabled = true;
            });
        }

        private void Button1_Click(object sender, RoutedEventArgs e) {
            try {
                this.network.Connect(Application.Current.Host.Source.Host);
            } catch(Exception ex) {
                ((Button)sender).Content = ex.Message;
            }
        }

        private void Button2_Click(object sender, RoutedEventArgs e) {
            this.network.SendCommand(new Quit());
        }
    }
}
